package com.bishe.demo.modules.hotel.common.dao;

import com.bishe.demo.modules.hotel.common.entity.HotelImage;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface HotelImageDao {
    @Insert("insert into hotel_image values(null,#{image})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertImage(HotelImage image);

    @Update("update hotel_image set image=#{image} where id=#{id}")
    void updateImage(HotelImage image);

    @Delete("delete from hotel_image where id=#{imageId}")
    void deleteImageByImageId(int imageId);

    @Select("select * from hotel_image where image_id=#{imageId}")
    HotelImage getImageByImageId(int imageId);

    @Select("select * from hotel_image")
    List<HotelImage> getAllImages();

    @Select("select * from hotel_image hi left join hotel_detail_hotel_image hdhi on hdhi.hotel_image_id=hi.id where hdhi.detail_id=#{detailId}")
    List<HotelImage> getImagesByDetailId(int detailId);

    @Select("select * from hotel_image hi left join hotel_facility_hotel_image hfhi on hfhi.hotel_image_id=hi.id where hfhi.facility_id=#{facilityId}")
    List<HotelImage> getImagesByFacilityId(int facilityId);

    @Select("select * from hotel_image hi left join hotel_room_hotel_image hrhi on hrhi.hotel_image_id=hi.id where hrhi.room_id=#{roomId}")
    List<HotelImage> getImagesByRoomId(int roomId);

}
